package exp07gui.chains;


public class MiddleHandler implements Handler {
    Handler next;

    @Override
    public void handle(int n) {
        if (n <= 20) {
            long s = 1;
            for (int i = 2; i <= n; i++) {
                s *= i;
            }
            System.out.println(String.format("%d!=%d", n, s));
        } else if (next != null) {
            next.handle(n);
        }
    }

    @Override
    public boolean setNextHandler(Handler next) {
        this.next = next;
        return true;
    }
}